import pagination from '@/views/pagination'  //分页组件
import Popup from './edit' //弹窗组件
import agentHttp from '@/utils/agentHttp.js'
import {
  debounce,
  timestampToTime
} from '@/utils/index.js'
export default {
  name: 'priceAudit',
  created() {
    this.seachData()
  },
  components: {
    Popup,pagination
  },
  data() {
    return {
      //搜索字段
      searchForm: {
        dealerName: "",
        status: "",
        orderNumber: "",
        startDate: "",
        endDate: "",
      },
      //表格字段
      tableData: [],
      userType:"",
      statusFnished :"FINISHED",
      id: null,
      formLabelWidth: '120px',
      statusMap: '',
      //发送给弹窗的数据
      dialogSendData: {
        isAdd: true, //是否为编辑或者新增  true是   false否
        dialogFormVisible: false, //弹窗是否显示        true是   false否
      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      endDateOpt: {
        disabledDate: (time) => {
          return time.getTime() < new Date(this.searchForm.startDate).getTime();
        }
      },

      resetFormStatus: false

    }
  },

  methods: {
    seachData() { //获取数据，现在是假的
      var params = this.searchForm || {};
      params.page = this.tableData.page || 1;
        params.rows = this.tableData.rows || 10;
      agentHttp.post('adminApi/admin/mortgage_contractinfo/get_mortgage_contractinfo_list', params).then((data) => {
        if (data.success) {
          this.tableData = data.data.contractList;
          this.userType = data.data.userType; 
        }
      }).catch(err => {

      })

    },
    formIsEdit(id) { //点击按钮，表单是否查看还是编辑
      console.dir(id)
      this.dialogSendData.dialogFormVisible = true;
      this.dialogSendData.isAdd = false;
      this.id = id;
    },
    getDate(time) {
      return timestampToTime(time)
    },
    openContract(id) {
      var newTab1 = window.open('about:loding....');
      agentHttp.get('adminApi/admin/contractinfo/view_yht_contract/' + id).then((data) => {
        if (data.success) {
          this.openWindow(newTab1, data.data);
        } else {
          this.$message.warning(data.err);
          newTab1.close();
        }
      })

    },
    handleDown(contractId) {
      if (contractId === null || contractId === "") {
        this.$message.warning('合同ID为空...');
        return;
      }
      var newTab = window.open('about:loding....');
      agentHttp.get('adminApi/admin/contractinfo/download_contract/' + contractId).then((data) => {
        this.openWindow(newTab, data);
      })
    },
    openWindow(obj, url) {
      obj.location.href = url;
    },
    resetSearchForm(formName) {
      this.$refs[formName].resetFields();
      this.seachData()
    },
    debounceSeach() { //input框内容发生改变时，调接口显示查询结果
      this.tableData.page = 1;
      debounce(this.seachData(this.searchForm), 1000)
    },
    changeQuey(){
      this.tableData.page=1;
      this.seachData();
    },
  }
}
